package org.pewpew.server;

import org.pewpew.model.WorldState;
import org.pewpew.server.persistence.DAO;

public class Persistence {

	private static final String DEFAULT_TYPE = "world";
	private static final String DEFAULT_ID = "test";

	public static void saveWorldState(String worldStateString) {
		DAO.storeData(DEFAULT_ID, DEFAULT_TYPE, worldStateString);
	}

	public static String getWorldStateString() {
		return getWorldState().toJSON();
	}
	
	public static WorldState getWorldState() {
		WorldState worldState = null;
		String data = DAO.getData(DEFAULT_ID, DEFAULT_TYPE);
		if (data == null) {
			worldState = new WorldState();
			data = worldState.toJSON();
			DAO.storeData(DEFAULT_ID, DEFAULT_TYPE, data);
		}
		
		return WorldState.fromJSON(data);
	}

}
